package au.com.bluelink.scjp.chap3;

public class WideningBoxingVarArgsTest {
	
	public static void main(String[] args) {

	}
	
}

// widening reference variables
class Animal {static void eat() { } } 
class Dog3 extends Animal { 
  public static void main(String[] args) { 
    Dog3 d = new Dog3(); 
    d.go(d);              // is this legal ? 
  } 
  void go(Animal a) { } 
} 

class EasyOver { 
	  static void go(int x) { System.out.print("int "); } 
	  static void go(long x) { System.out.print("long "); } 
	  static void go(double x) { System.out.print("double "); } 
	  public static void main(String [] args) { 
	    byte b = 5; 
	    short s = 5; 
	    long l = 5; 
	    float f = 5.0f; 
	    go(b); 
	    go(s); 
	    go(l); 
	    go(f); 
	  } 
	}

class AddBoxing { 
	  static void go(Integer x) { System.out.println("Integer"); } 
	  static void go(long x) { System.out.println("long"); } 
	  public static void main(String [] args) { 
	    int i = 5; 
	    go(i);           // which go() will be invoked? 
	  } 
	} 

class AddVarargs { 
	  static void go(int x, int y) { System.out.println("int,int");} 
	  static void go(byte... x) { System.out.println("byte... "); } 
	  public static void main(String[] args) { 
	    byte b = 5; 
	    go(b,b);         // which go() will be invoked? 
	  } 
	} 

class BoxOrVararg { 
	  static void go(Byte x, Byte y)  
	                { System.out.println("Byte, Byte"); } 
	  static void go(byte... x) { System.out.println("byte... "); } 
	  public static void main(String [] args) { 
	    byte b = 5; 
	    go(b,b);         // which go() will be invoked? 
	  } 
	} 

class BoxAndWiden { 
	  static void go(Object o) { 
	    Byte b2 = (Byte) o;       // ok - it's a Byte object 
	    System.out.println(b2); 
	  } 
	  public static void main(String [] args) { 
	    byte b = 5; 
	    go(b);       // can this byte turn into an Object ? 
	  } 
	}

class Vararg { 
	  static void wide_vararg(long... x)  
	              { System.out.println("long..."); } 
	  static void box_vararg(Integer... x)  
	              { System.out.println("Integer..."); } 
	  public static void main(String [] args) { 
	    int i = 5; 
	    wide_vararg(5,5);    // needs to widen and use var-args 
	    box_vararg(5,5);     // needs to box and use var-args 
	  } 
	} 







